from sqlalchemy import Column, Integer, String, Text
from sqlalchemy.orm import declarative_base, sessionmaker
from database.mysql_utils import MysqlUtils

Base = declarative_base()


class Role(Base):
    __tablename__ = 'role'
    id = Column(Integer, primary_key=True)
    role = Column(String(255))


Base.metadata.create_all(MysqlUtils.mysql_connect())
Session = sessionmaker(bind=MysqlUtils.mysql_connect())


class RoleData:

    @staticmethod
    def insert_role_info():
        session = Session()
        role_list = ["总经理", "副总经理", "运营总监", "运营", "广告总监", "广告", "助理", "技术", "美工", "供应链",
                     "货物", "库房", "机器人"]
        for role in role_list:
            role_obj = Role(role=role)
            session.add(role_obj)
        session.commit()
        session.close()

    @staticmethod
    def get_role_list():
        session = Session()
        ret = session.query(Role.role).all()
        role_list = [role_obj[0] for role_obj in ret]
        print(role_list)
        return role_list


if __name__ == '__main__':
    RoleData.get_role_list()
